import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/home/index.vue'
import FooterNav from '@/components/FooterNav.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    alias: '/home',
    components: {
      default: Home,
      foot: FooterNav
    }
  },
  {
    path: '/kind',
    name: 'Kind',
    components: {
      default: () => import(/* webpackChunkName: "kind" */ '../views/kind/index.vue'),
      foot: FooterNav
    }
  },
  {
    path: '/cart',
    name: 'Cart',
    components: {
      default: () => import(/* webpackChunkName: "pro" */ '../views/cart/index.vue')
    }
  },
  {
    path: '/mine',
    name: 'Mine',
    components: {
      default: () => import(/* webpackChunkName: "user" */ '../views/mine/index.vue'),
      foot: FooterNav
    },
    // 单个路由守卫
    beforeEnter: (to, from, next) => {
      if (sessionStorage.getItem('isLogin') === 'ok') {
        next()
      } else {
        next('/login')
      }
    }
  },
  {
    path: '/detail/:id',
    name: 'Detail',
    components: {
      default: () => import(/* webpackChunkName: "detail" */ '../views/detail/index.vue')
    }
  },
  {
    path: '/search',
    name: 'Search',
    components: {
      default: () => import(/* webpackChunkName: "search" */ '../views/search/index.vue')
    }
  },
  {
    path: '/searchRes/:s',
    name: 'SearchRes',
    components: {
      default: () => import(/* webpackChunkName: "search" */ '../views/searchRes/index.vue')
    },
    props: {
      default: true
    }
  },
  {
    path: '/register',
    name: 'Register',
    components: {
      default: () => import(/* webpackChunkName: "user" */ '../views/register/index.vue')
    }
  },
  {
    path: '/order',
    name: 'Order',
    components: {
      default: () => import(/* webpackChunkName: "user" */ '../views/order/index.vue')
    }
  },
  {
    path: '/login',
    name: 'Login',
    components: {
      default: () => import(/* webpackChunkName: "user" */ '../views/login/index.vue')
    }
  }
]

const router = new VueRouter({
  routes
})

export default router
